<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ include file="/taglibs.jsp"%>
<html>
<head>
<title>IT管理后台</title>
<link rel="stylesheet" type="text/css" href="/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="/js/themes/icon.css">
<script type="text/javascript" src="/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/js/easyui_validatebox.js"></script>
<script type="text/javascript" src="/js/locale/easyui-lang-zh_CN.js"></script>
<script src="/js/print.js" type="text/javascript"></script>
<style type="text/css">
td {
	font-size: 13px
}
table.ttb{border-left:solid 1px #99bbe8;border-top: solid 1px #99bbe8;}
table.ttb td{word-break: break-all; word-wrap:break-word;vertical-align: top; padding-left:8px; border-right: solid 1px #99bbe8;border-bottom: solid 1px #99bbe8; line-height: 24px; font-size: 12px;}
.bg001{font-weight: bold; color: #333; background-color: #edf4fc}
</style>
	<script>
		$(function(){
			$('#tab').datagrid({
				title:'员工信息',
				iconCls:'icon-save',
				nowrap: false,
				striped: true,
				pageSize:20,
				sortName:"id",
				sortOrder:"desc",
				pageList:[10,20,30,40,50],
				url:'/itmanager/yg/json',
				remoteSort: false,
				idField:'id',
				frozenColumns:[[
	                	{field:'ck',checkbox:true},
	                	{title:'员工编号',field:"ygbh",width:80},
						{title:'部门',field:"bmmc",width:80},
						{title:'职位',field:"zwmc",width:80},
						{title:'姓名',field:"xm",width:80},
						{title:'性别',field:"xb",width:40,formatter:
					    	 function(value,rowData,rowIndex){
								if(value=="0"){
									return "<font color='red'>男</font>";
								}else if(value=="1"){
									return "<font color='red'>女</font>";
								}
							}
						}
	                ]],
				columns:[
					[
						{title:"联系电话",field:"lxdh",width:80},
					    {title:'年龄',field:"nl",width:80}
					]
				],
				fit:true,
				fitColumns:false,
				border:false,
				pagination:true,
				rownumbers:true,
				toolbar:[{
					id:'1',
					text:'添加',
					disabled:true,
					iconCls:'icon-add',
					handler:function(){
						ygadd.window({
							onBeforeOpen:function(){
								ygaddform.form('clear');
								$("#xb-add").val("0");
								$.ajax({
									   type: "get",
									   url: "/itmanager/common/cllx",
									   data: "lx=bm",
									   success: function(msg){
										   var bmm = $("#bm-add")[0];  //把jquery对象转成dom对象使用
										   clearSel(bmm); //清空
										   msg=$.parseJSON(msg);
										   $.each(msg, function(i, b) {
												var value = b.id;
												var text = b.clmc;
												var option = new Option(text, value);
												bmm.options.add(option);
											});
									   }
									});
								$.ajax({
									   type: "get",
									   url: "/itmanager/common/cllx",
									   data: "lx=zw",
									   success: function(msg){
										   var zww = $("#zw-add")[0];  //把jquery对象转成dom对象使用
										   clearSel(zww); //清空
										   msg=$.parseJSON(msg);
										   $.each(msg, function(i, b) {
												var value = b.id;
												var text = b.clmc;
												var option = new Option(text, value);
												zww.options.add(option);
											});
									   }
									});
							}
						});
						ygadd.window("open");
					}
				},'-',{
					id:'2',
					text:'修改',
					disabled:true,
					iconCls:'icon-edit',
					handler:function(){
						ygedit.window({
							onBeforeOpen:function(){
								ygeditform.form('clear');
								var rows = $("#tab").datagrid("getSelections");
								var length = rows.length;
								if(length != 1){
									$.messager.alert("友情提示","<br/><b>只能选择一条记录！</b>","error");
									return false;
								}
								var id=rows[0].id;
								$.ajax({
									   type: "get",
									   url: "/itmanager/common/cllx",
									   data: "lx=bm",
									   success: function(msg){
										   var bmm = $("#bm-edit")[0];  //把jquery对象转成dom对象使用
										   clearSel(bmm); //清空
										   msg=$.parseJSON(msg);
										   $.each(msg, function(i, b) {
												var value = b.id;
												var text = b.clmc;
												var option = new Option(text, value);
												bmm.options.add(option);
											});
									   }
									});
								$.ajax({
									   type: "get",
									   url: "/itmanager/common/cllx",
									   data: "lx=zw",
									   success: function(msg){
										   var zww = $("#zw-edit")[0];  //把jquery对象转成dom对象使用
										   clearSel(zww); //清空
										   msg=$.parseJSON(msg);
										   $.each(msg, function(i, b) {
												var value = b.id;
												var text = b.clmc;
												var option = new Option(text, value);
												zww.options.add(option);
											});
									   }
									});
								$.ajax({
							 		type:"get",
							 		url:"/itmanager/yg/show",
							 		data:"id="+id,
							 		cache:false,
							 		success:function(data){
							 		 	data=$.parseJSON(data);
										$("#ygbh-edit").val(data.ygbh);
										$("#bm-edit").val(data.bm);
										$("#zw-edit").val(data.zw);
										$("#xm-edit").val(data.xm);
										$("#lxdh-edit").val(data.lxdh);
										$("#nl-edit").val(data.nl);
										$("#xb-edit").val(data.xb);
							 		}
							 	});
							}
						});
						ygedit.window("open");
					}
				},'-',{
					id:'11',
					text:'查看详情',
					disabled:true,
					iconCls:'icon-search',
					handler:function(){
						show();
					}
				},'-',{
					id:'3',
					text:'删除',
					disabled:true,
					iconCls:'icon-remove',
					handler:function(){
						deleteYg();
					}
				},'-',{
					id:'9',
					text:'打印',
					disabled:true,
					iconCls:'icon-print',
					handler:function(){
						startPrint($(".datagrid-view")[0]);
					}
				}]
			});
			
			 $("#tab").datagrid("getPager").pagination({
				   onSelectPage:function(){
					  $("#tab").datagrid("clearSelections");
					  var queryParams = $.extend({},$("#tab").datagrid("options").queryParams,
							  {spxm:$("#xm-search").val(),spxb:$("#xb-search").val(),spbm:$("#bm-search").val()}); 
					  $("#tab").datagrid("reload",queryParams);
				   }
			  });
			 
			yg = $('#yg-window').window({
				modal: true,
				maximizable:false,
				minimizable:false,
				collapsible:false,
				closed:true
			});
			ygadd = $('#yg-add').window({
				modal: true,
				maximizable:false,
				minimizable:false,
				collapsible:false,
				closed:true
			});
			ygaddform=ygadd.find("form");
			ygedit = $('#yg-edit').window({
				modal: true,
				maximizable:false,
				minimizable:false,
				collapsible:false,
				closed:true
			});
			ygedit.window({
				onBeforeClose:function(){
					var queryParams = $.extend({},$("#tab").datagrid("options").queryParams);
		 			$("#tab").datagrid("reload",queryParams);
				}
			});
			ygeditform=ygedit.find("form");
			
			 var ens='${param.en}';
			 var en=ens.split(":");
			 for(var i=0;i<en.length;i++){
				 if(en[i] != "" && en[i] != null){
				 	$("#"+en[i]).linkbutton('enable');
				 }
			 }
			
		});
		
		var find = function(){
			$("#tab").datagrid("clearSelections");
			var queryParams = $.extend({},$("#tab").datagrid("options").queryParams,
					{spxm:$("#xm-search").val(),spxb:$("#xb-search").val(),spbm:$("#bm-search").val()}); 
			$("#tab").datagrid("getPager").pagination({pageNumber:1});
			$("#tab").datagrid("reload",queryParams);
		}
		
		var show=function(){
			var rows = $("#tab").datagrid("getSelections");
			var length = rows.length;
			if(length != 1){
				$.messager.alert("友情提示","<br/><b>只能选择一条记录！</b>","error");
				return false;
			}
			var id=rows[0].id;
			$.ajax({
		 		type:"get",
		 		url:"/itmanager/yg/show",
		 		cache: false,
		 		data:"id="+id,
		 		success:function(data){
		 		 	yg.window("open");
		 		 	data=$.parseJSON(data);
					var sign="=>>";
					mtext("#yg-ygbh",data.ygbh);
					mtext("#yg-bm",data.bmmc);
					mtext("#yg-zw",data.zwmc);
					mtext("#yg-xm",data.xm);
					mtext("#yg-lxdh",data.lxdh);
					mtext("#yg-nl",data.nl);
					var xb=data.xb;
					if(xb=='0'){
						mtext("#yg-xb","男");
					}else if(xb=='1'){
						mtext("#yg-xb","女");
					}
					
		 		}
		 	});
		}
		
		function mtext(target,text){
			$(target).html("&nbsp;");
			$(target).html(text);
		}
		
		function clearSel(oSelect) {
			while (oSelect.childNodes.length > 0) {
				oSelect.removeChild(oSelect.childNodes[0]);
			}

		}
		
		function closeYgadd(){
			ygadd.window('close');
		}
		function closeYgedit(){
			ygedit.window('close');
		}
		
		function createYg(){
			ygaddform.form('submit', {  
				  url:ygaddform.action,
				  onSubmit:function(){
				        return $(this).form('validate');
				    },
				  success:function(data){
				          if (data=='success'){  
				        	  	$.messager.alert('信息提示','添加成功！','right');  
				                ygadd.window('close');  
				                var queryParams = $.extend({},$("#tab").datagrid("options").queryParams);
					 			$("#tab").datagrid("reload",queryParams);
				            } else if(data=='error'){
				            	$.messager.alert('信息提示','添加失败！','error');
				            }
				     }  
			});  
		}
		
		function editYg(){
			var rows = $("#tab").datagrid("getSelections");
			var length = rows.length;
			if(length != 1){
				$.messager.alert("友情提示","<br/><b>只能选择一条记录！</b>","error");
				return false;
			}
			var id=rows[0].id;
			ygeditform.form('submit', {  
				  url:"/itmanager/yg/edit?id="+id,
				  onSubmit:function(){
				        return $(this).form('validate');
				    },
				  success:function(data){
				          if (data=='success'){  
				        	  	$.messager.alert('信息提示','修改成功！','right');  
				                
				            } else if(data=='error'){
				            	$.messager.alert('信息提示','修改失败！','error');
				            }
				     }  
			});  
		}
		
		var deleteYg = function(){
			var rows = $("#tab").datagrid("getSelections");
			var length = rows.length;
			if(length == 0){
				$.messager.alert("友情提示","<br/><b>请先选择记录！</b>","error");
				return false;
			}
			var ids = [];
			for(var i=0;i<length;i++){
				ids.push(rows[i].id);
			}
			ids.join(",");
			$.messager.confirm("友情提示","<br/><b>确定删除记录？</b>",function(result){
				if(result){
					$.ajax({
				 		type:"post",
				 		url:"/itmanager/yg/delete",
				 		data:"ids="+ids,
				 		success:function(data){
				 			if(data=='success'){
				 		 		var queryParams = $.extend({},$("#tab").datagrid("options").queryParams);
				 				$("#tab").datagrid("reload",queryParams);
				 				$("#tab").datagrid("clearSelections");
				 			}else if(data=='error'){
				 				$.messager.alert("友情提示","<br/><b>删除记录出错！</b>","error");
				 			}
				 		}
				 	});
				}
			});
		} 
		
		
		
		/* var sh = function(param){
			var rows = $("#tab").datagrid("getSelections");
			var length = rows.length;
			if(length == 0){
				$.messager.alert("友情提示","<br/><b>请先选择记录！</b>","error");
				return false;
			}
			var ids = [];
			for(var i=0;i<length;i++){
				ids.push(rows[i].id);
			}
			ids.join(",");
		 	$.ajax({
		 		type:"post",
		 		url:"/manager/yg/sh",
		 		data:"shqk="+param+"&ids="+ids,
		 		success:function(data){
		 		 	var queryParams = $.extend({},$("#tab").datagrid("options").queryParams);
		 			$("#tab").datagrid("reload",queryParams);
		 			$("#tab").datagrid("clearSelections");
		 		}
		 	});
		} */
		
	</script>
</head>
<body class="easyui-layout">
	<div region="north" border="false" style="height:80px;" iconCls="icon-search" title="查询条件">
		<table width="100%" height="100%" style="background-color:#E0ECFF ">
			<thead>
				<tr>
					<td width="10%" align="center">员工姓名：</td>
					<td width="20%"><input type="text" name="spxm" id="xm-search" value="${smap.spxm }"></td>
					<td width="10%" align="center">性别：</td>
					<td width="20%">
						<select name="spxb" id="xb-search">
							<option value="">-请选择-</option>
							<option value="0">男</option>
							<option value="1">女</option>
						</select>
					</td>
					<td width="10%" align="center">所属部门：</td>
					<td width="20%">
						<select name="spbm" id="bm-search">
							<option value="">--请选择部门--</option>
							<c:forEach items="${bm }" var="b">
								<option value="${b.id }" <c:if test="${smap.spbm==b.clmc }">selected</c:if>>${b.clmc }</option>
							</c:forEach>
						</select>
					</td>
					<td><a id="4" disabled="true" class="easyui-linkbutton" iconCls="icon-search" onclick="find()">查询</a></td>
				</tr>
			</thead>
		</table>
	</div>
	<div id="center" region="center">
		<table id="tab"></table>
	</div>
	
	<div id="yg-window" title="查看员工详情" style="width:500px;">
				
		<table class="ttb" border="0" cellspacing="0" cellpadding="0" width="100%">
							<tr>
								<td nowrap="nowrap" class="bg001" class="bg001">员工编号：</td>
								<td id="yg-ygbh">&nbsp;</td>
								<td nowrap="nowrap" class="bg001" class="bg001">所属部门：</td>
								<td id="yg-bm">&nbsp;</td>
								<td nowrap="nowrap" class="bg001">职位：</td>
								<td id="yg-zw">&nbsp;</td>
								<td nowrap="nowrap" class="bg001">姓名：</td>
								<td id="yg-xm">&nbsp;</td>
							</tr>
							<tr>
								<td nowrap="nowrap" class="bg001">性别：</td>
								<td id="yg-xb">&nbsp;</td>
								<td nowrap="nowrap" class="bg001">联系电话：</td>
								<td id="yg-lxdh">&nbsp;</td>
								<td nowrap="nowrap" class="bg001">年龄：</td>
								<td id="yg-nl" colspan="3">&nbsp;</td>
							</tr>
									
		</table>
					
	</div>
	
	
	<div id="yg-add" title="添加员工" style="width:350px;height:300px;">
				<div style="text-align: center;padding-top: 5px;">
					<form method="post" action="/itmanager/yg/add">
						<table>
							<tr>
								<td>员工编号：</td>
								<td><input name="ygbh" id="ygbh-add" type="text" class="easyui-validatebox" required="true"></input></td>
							</tr>
							<tr>
								<td>部门：</td>
								<td>
									<select name="bm" id="bm-add" style="width:150px;">
									</select>
								</td>
							</tr>
							<tr>
								<td>职位：</td>
								<td>
									<select name="zw" id="zw-add" style="width:150px;">
									</select>
								</td>
							</tr>
							<tr>
								<td>员工姓名：</td>
								<td><input name="xm" id="xm-add" type="text" class="easyui-validatebox" required="true"></input></td>
							</tr>
							<tr>
								<td>性别：</td>
								<td><select name="xb" id="xb-add" style="width:150px;">
									<option value="0">男</option>
									<option value="1">女</option>
								</select></td>
							</tr>
							<tr>
								<td>联系电话：</td>
								<td><input name="lxdh" id="lxdh-add" type="text"></input></td>
							</tr>
							<tr>
								<td>年龄：</td>
								<td><input name="nl" id="nl-add" type="text"></input></td>
							</tr>
						</table>
					</form>
				</div>
				<div style="text-align:center;">
					<a href="javascript:void(0)" onclick="createYg()" class="easyui-linkbutton" id="yg-add-button" icon="icon-save">添加</a>
					<a href="javascript:void(0)" onclick="closeYgadd()" class="easyui-linkbutton" id="yg-cancel-button" icon="icon-cancel">取消</a>
				</div>
		</div>
		
		<div id="yg-edit" title="修改员工信息" style="width:350px;height:300px;">
				<div style="text-align: center;padding-top: 5px;">
					<form method="post" action="/itmanager/yg/edit">
						<table>
							<tr>
								<td>员工编号：</td>
								<td><input name="ygbh" id="ygbh-edit" type="text" class="easyui-validatebox" required="true"></input></td>
							</tr>
							<tr>
								<td>部门：</td>
								<td>
									<select name="bm" id="bm-edit" style="width:140px;">
									</select>
								</td>
							</tr>
							<tr>
								<td>职位：</td>
								<td>
									<select name="zw" id="zw-edit" style="width:140px;">
									</select>
								</td>
							</tr>
							<tr>
								<td>员工姓名：</td>
								<td><input name="xm" id="xm-edit" type="text" class="easyui-validatebox" required="true"></input></td>
							</tr>
							<tr>
								<td>性别：</td>
								<td><select name="xb" id="xb-edit" style="width:140px;">
									<option value="0">男</option>
									<option value="1">女</option>
								</select></td>
							</tr>
							<tr>
								<td>联系电话：</td>
								<td><input name="lxdh" id="lxdh-edit" type="text"></input></td>
							</tr>
							<tr>
								<td>年龄：</td>
								<td><input name="nl" id="nl-edit" type="text"></input></td>
							</tr>
						</table>
					</form>
				</div>
				<div style="text-align:center;">
					<a href="javascript:void(0)" onclick="editYg()" class="easyui-linkbutton" id="yg-edit-button" icon="icon-ok">修改</a>
					<a href="javascript:void(0)" onclick="closeYgedit()" class="easyui-linkbutton" id="yg-cancel-button" icon="icon-cancel">取消</a>
				</div>
		</div>

</body>
</html>